{%- set vfs_objects = salt['pillar.get']('default:OMV_SAMBA_SHARE_VFSOBJECTS', '') -%}
{%- set recycle_repository = salt['pillar.get']('default:OMV_SAMBA_SHARE_RECYCLE_REPOSITORY', '.recycle/%U') -%}
{%- set recycle_keeptree = salt['pillar.get']('default:OMV_SAMBA_SHARE_RECYCLE_KEEPTREE', 'yes') -%}
{%- set recycle_versions = salt['pillar.get']('default:OMV_SAMBA_SHARE_RECYCLE_VERSIONS', 'yes') -%}
{%- set recycle_touch = salt['pillar.get']('default:OMV_SAMBA_SHARE_RECYCLE_TOUCH', 'yes') -%}
{%- set recycle_touch_mtime = salt['pillar.get']('default:OMV_SAMBA_SHARE_RECYCLE_TOUCH_MTIME', 'no') -%}
{%- set recycle_directory_mode = salt['pillar.get']('default:OMV_SAMBA_SHARE_RECYCLE_DIRECTORYMODE', '0777') -%}
{%- set recycle_subdir_mode = salt['pillar.get']('default:OMV_SAMBA_SHARE_RECYCLE_SUBDIRMODE', '0700') -%}
{%- set recycle_exclude = salt['pillar.get']('default:OMV_SAMBA_SHARE_RECYCLE_EXCLUDE', '*.tmp, *.TMP, *.temp, *.TEMP, *.~lock*, *.o, *.obj, ~$*, ~*.*') -%}
{%- set recycle_exclude_dir = salt['pillar.get']('default:OMV_SAMBA_SHARE_RECYCLE_EXCLUDEDIR', '/cache, /CACHE, /recycle, /RECYCLE, /tmp, /TMP, /temp, /TEMP') -%}
{%- set recycle_noversions = salt['pillar.get']('default:OMV_SAMBA_SHARE_RECYCLE_NOVERSIONS', '*.tmp, *.TMP, *.temp, *.TEMP, *.o, *.obj, ~*.*') -%}
{%- set full_audit_prefix = salt['pillar.get']('default:OMV_SAMBA_SHARE_AUDIT_PREFIX', '%u|%I|%m|%P|%S') -%}
{%- set full_audit_success = salt['pillar.get']('default:OMV_SAMBA_SHARE_AUDIT_SUCCESS', 'mkdirat renameat unlinkat pwrite') -%}
{%- set full_audit_failure = salt['pillar.get']('default:OMV_SAMBA_SHARE_AUDIT_FAILURE', 'connect') -%}
{%- set full_audit_facility = salt['pillar.get']('default:OMV_SAMBA_SHARE_AUDIT_FACILITY', 'local7') -%}
{%- set full_audit_priority = salt['pillar.get']('default:OMV_SAMBA_SHARE_AUDIT_PRIORITY', 'NOTICE') -%}
{%- set printable = salt['pillar.get']('default:OMV_SAMBA_SHARE_PRINTABLE', 'no') -%}
{%- set create_mask = salt['pillar.get']('default:OMV_SAMBA_SHARE_CREATEMASK', '0664') -%}
{%- set force_create_mode = salt['pillar.get']('default:OMV_SAMBA_SHARE_FORCECREATEMODE', '0664') -%}
{%- set directory_mask = salt['pillar.get']('default:OMV_SAMBA_SHARE_DIRECTORYMASK', '0775') -%}
{%- set force_directory_mode = salt['pillar.get']('default:OMV_SAMBA_SHARE_FORCEDIRECTORYMODE', '0775') -%}
{%- set hide_special_files = salt['pillar.get']('default:OMV_SAMBA_SHARE_HIDESPECIALFILES', 'yes') -%}
{%- set fruit_locking = salt['pillar.get']('default:OMV_SAMBA_SHARE_FRUIT_LOCKING', 'none') -%}
{%- set fruit_encoding = salt['pillar.get']('default:OMV_SAMBA_SHARE_FRUIT_ENCODING', 'private') -%}
{%- set fruit_metadata = salt['pillar.get']('default:OMV_SAMBA_SHARE_FRUIT_METADATA', 'stream') -%}
{%- set fruit_resource = salt['pillar.get']('default:OMV_SAMBA_SHARE_FRUIT_RESOURCE', 'file') -%}
{%- set fruit_veto_appledouble = salt['pillar.get']('default:OMV_SAMBA_SHARE_FRUIT_VETOAPPLEDOUBLE', 'no') -%}
{%- set fruit_wipe_intentionally_left_blank_rfork = salt['pillar.get']('default:OMV_SAMBA_SHARE_FRUIT_WIPEINTENTIONALLYLEFTBLANKRFORK', 'yes') -%}
{%- set fruit_delete_empty_adfiles = salt['pillar.get']('default:OMV_SAMBA_SHARE_FRUIT_DELETEEMPTYADFILES', 'yes') -%}
{%- set shadow_sort = salt['pillar.get']('default:OMV_SAMBA_SHARE_SHADOW_SORT', 'desc') -%}
{%- set dfree_command = salt['pillar.get']('default:OMV_SAMBA_SHARE_DFREECOMMAND', '/usr/sbin/omv-btrfs-dfree') -%}
{%- set dfree_cache_time = salt['pillar.get']('default:OMV_SAMBA_SHARE_DFREECACHETIME', '30') -%}
#======================= Share Definitions =======================
{%- for share in config.shares.share | selectattr('enable') %}
{%- set sf_name = salt['omv_conf.get_sharedfolder_name'](share.sharedfolderref) %}
{%- set sf_path = salt['omv_conf.get_sharedfolder_path'](share.sharedfolderref) %}
[{{ sf_name }}]
{%- if share.comment | length > 0 %}
comment = {{ share.comment }}
{%- endif %}
path = {{ sf_path }}
guest ok = {{ (share.guest != 'no') | yesno }}
guest only = {{ (share.guest == 'only') | yesno }}
read only = {{ share.readonly | to_bool | yesno }}
browseable = {{ share.browseable | to_bool | yesno }}
inherit acls = {{ share.inheritacls | to_bool | yesno }}
inherit permissions = {{ share.inheritpermissions | to_bool | yesno }}
ea support = {{ share.easupport | to_bool | yesno }}
store dos attributes = {{ share.storedosattributes | to_bool | yesno }}
{%- if share.transportencryption | to_bool %}
smb encrypt = required
{%- endif %}
{%- set vfs_objects = vfs_objects.split(' ') %}
{%- if share.audit | to_bool %}
{%- set _ = vfs_objects.append('full_audit') %}
full_audit:prefix = {{ full_audit_prefix }}
full_audit:success = {{ full_audit_success }}
full_audit:failure = {{ full_audit_failure }}
full_audit:facility = {{ full_audit_facility }}
full_audit:priority = {{ full_audit_priority }}
{%- endif %}
{%- if enable_timemachine_vfs | to_bool %}
{%- set _ = vfs_objects.append('fruit') %}
{%- set _ = vfs_objects.append('streams_xattr') %}
{%- endif %}
{%- if share.timemachine | to_bool %}
fruit:encoding = {{ fruit_encoding }}
fruit:locking = {{ fruit_locking }}
fruit:metadata = {{ fruit_metadata }}
fruit:resource = {{ fruit_resource }}
fruit:veto_appledouble = {{ fruit_veto_appledouble }}
fruit:wipe_intentionally_left_blank_rfork = {{ fruit_wipe_intentionally_left_blank_rfork }}
fruit:delete_empty_adfiles = {{ fruit_delete_empty_adfiles }}
fruit:time machine = yes
{%- endif %}
{%- if share.recyclebin | to_bool %}
{%- set _ = vfs_objects.append('recycle') %}
recycle:repository = {{ recycle_repository }}
recycle:keeptree = {{ recycle_keeptree }}
recycle:versions = {{ recycle_versions }}
recycle:touch = {{ recycle_touch }}
recycle:touch_mtime = {{ recycle_touch_mtime }}
recycle:directory_mode = {{ recycle_directory_mode }}
recycle:subdir_mode = {{ recycle_subdir_mode }}
recycle:exclude = {{ recycle_exclude }}
recycle:exclude_dir = {{ recycle_exclude_dir }}
recycle:noversions = {{ recycle_noversions }}
recycle:maxsize = {{ share.recyclemaxsize }}
{%- endif %}
{%- if share.sharedfolderref | omv_conf_get_by_identifier('conf.system.sharedfolder') | attr('mntentref') | omv_conf_get_by_identifier('conf.system.filesystem.mountpoint') | attr('type') == 'btrfs' %}
{%- set _ = vfs_objects.append('btrfs') %}
{%- set _ = vfs_objects.append('shadow_copy2') %}
{%- set sf_mount_path = salt['omv_conf.get_sharedfolder_mount_path'](share.sharedfolderref) %}
shadow:mountpoint = {{ sf_mount_path }}
shadow:snapdir = {{ sf_mount_path | path_join('.snapshots') | path_prettify }}
shadow:basedir = {{ sf_path }}
shadow:sort = {{ shadow_sort }}
shadow:format = _%Y%m%dT%H%M%S
shadow:delimiter = _
shadow:snapprefix = ^{{ sf_name }}\(@hourly\)\{0,1\}\(@daily\)\{0,1\}\(@weekly\)\{0,1\}\(@monthly\)\{0,1\}\(@yearly\)\{0,1\}$
shadow:localtime = no
dfree command = {{ dfree_command }}
dfree cache time = {{ dfree_cache_time }}
{%- endif %}
vfs objects = {{ vfs_objects | unique | join(' ') }}
printable = {{ printable }}
create mask = {{ create_mask }}
force create mode = {{ force_create_mode }}
directory mask = {{ directory_mask }}
force directory mode = {{ force_directory_mode }}
hide special files = {{ hide_special_files }}
follow symlinks = {{ share.followsymlinks | to_bool | yesno }}
wide links = {{ share.widelinks | to_bool | yesno }}
{%- if share.hostsallow | length > 0 %}
hosts allow = {{ share.hostsallow }}
{%- endif %}
{%- if share.hostsdeny | length > 0 %}
hosts deny = {{ share.hostsdeny }}
{%- endif %}
hide dot files = {{ share.hidedotfiles | to_bool | yesno }}
{%- set sf_config = salt['omv_conf.get']('conf.system.sharedfolder', share.sharedfolderref) -%}
{%- set validusers = [] -%}
{%- set invalidusers = [] -%}
{%- set readlist = [] -%}
{%- set writelist = [] -%}
{%- for privilege in sf_config.privileges.privilege -%}
{%- set name = '"' ~ privilege.name ~ '"' -%}
{%- if privilege.type == 'group' -%}
{%- set name = '@' ~ name -%}
{%- endif %}
{%- if privilege.perms == 0 -%}
{%- set _ = invalidusers.append(name) -%}
{%- elif privilege.perms == 5 -%}
{%- set _ = readlist.append(name) -%}
{%- set _ = validusers.append(name) -%}
{%- elif privilege.perms == 7 -%}
{%- set _ = writelist.append(name) -%}
{%- set _ = validusers.append(name) -%}
{%- endif %}
{%- endfor %}
{%- if share.guest != 'only' %}
{%- if share.guest == 'no' %}
valid users = {{ validusers | join(',') }}
invalid users = {{ invalidusers | join(',') }}
{%- endif %}
read list = {{ readlist | join(',') }}
{%- if not share.readonly | to_bool %}
write list = {{ writelist | join(',') }}
{%- endif %}
{%- endif %}
{%- if share.extraoptions | length > 0 %}
{{ share.extraoptions }}
{%- endif %}
{% endfor %}
